// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'
import Vuex from 'vuex'

Vue.config.productionTip = false
/*console.log('单次请求')
axios.post('https://www.easy-mock.com/mock/5b0e0bc19a9dc61094244547/today/user/login',{}).then(data => {
  console.log(data.data)
}).catch(error => {
})
console.log('多次同时请求-start')
function getUserAccount() {
  return axios.get('https://www.easy-mock.com/mock/5b0e0bc19a9dc61094244547/today/query');
}
function getUserPermissions() {
  return axios.get('https://www.easy-mock.com/mock/5b0e0bc19a9dc61094244547/today/')
}
axios.all([getUserAccount(), getUserPermissions()])
  .then(axios.spread(function (acct, perms) {
    // 两个请求现在都执行完成
    console.log('多次同时请求-result')
    console.log(acct.data);
    console.log(perms.data)
  }));
console.log('多次同时请求-end')

console.log('axios-config传入-start')
function axiosM(config) {
  return axios(config);
}
axiosM({
  method: 'get',
  url: 'https://www.easy-mock.com/mock/5b0e0bc19a9dc61094244547/today/',
  data: {
    firstName: 'Fred',
    lastName: 'Flintstone'
  }
}).then(value => {
  console.log(value.data)
}).catch(error => {
  console.log(error)
})
console.log('axios-config传入-end')*/

/*const axiosObj =  axios.create({
  baseURL: 'https://www.easy-mock.com/mock/5b0e0bc19a9dc61094244547/today',
  timeout: 3500
})
axiosObj.get('/',{
  method: 'get',
}).then(data => {
  console.log(data.data)
})*/

/*
new Vue({
  // state
  data() {
    return {
      count: 0
    }
  },
  // view
  template: `
    <div>{{ count }}</div>
  `,
  // action
  methods: {
    increment() {
      this.count++;
    }
  }
})
*/

Vue.use(Vuex)

/* vuex最简单的实现与调用 start */
/*const store = new Vuex.Store({
  state: {
    count: 0
  },
  mutations: {
    increment(state) {
      state.count++
    }
  }
})*/
/* vuex最简单的实现与调用 end */
/* 计算属性中返回某个状态值 start */
/*const Counter = {
  template: `<div>{{ count }}</div>`,
  computed: {
    count() {
      return this.$store.state.count
    }
  }
}*/
/* 计算属性中返回某个状态值 end */

/*const store = new Vuex.Store({
  state: {
    todos: [
      {id: 1, text: '...', done: true},
      {id: 2, text: '...', done: true},
    ]
  },
  getters: {
    doneTodos: state => id => {
      // return state.todos.filter(todo => todo.done)
      return state.todos.find(item => item.id === id)
    }
  }
})*/
// getters 对外暴露为 store.getters 对象
/*console.log(store.getters.doneTodos(2))*/
/*store.commit('increment')
console.log('count = ' + store.state.count)*/
import { mapState } from 'vuex'

/*const store = new Vuex.Store({
  state: {
    count: 1
  },
  mutations: {
    increment(state) {
      state.count++
    }
  }
})
store.commit('increment');
console.log(store.state.count)*/

new Vue({
  el: '#app',
  components: { App },
  /*template: '<APP/>',*/
  template: '<App/>'
})


